home *** CD-ROM | disk | FTP | other *** search
- /*
- api/submit.js
-
- Copyright © 2005, 2006, 2007 Against Intuition, Inc. <info@mywot.com>
- */
-
- var wot_api_submit =
- {
- init: function()
- {
- },
-
- send: function(prefname, target, testimonies)
- {
- try {
- if (!wot_api_register.ready) {
- return;
- }
-
- if (!prefname || prefname.charAt(0) != '.' || !target ||
- !testimonies) {
- return;
- }
-
- var hostname = wot_url.gethostname(target);
-
- if (!hostname) {
- return;
- }
-
- var nonce = wot_crypto.nonce();
- var context =
- wot_arc4.create(wot_hash.hmac_sha1hex(wot_prefs.witness_key,
- nonce));
-
- if (!context) {
- return;
- }
-
- var crypted_target =
- wot_arc4.crypt(context, wot_hash.strtobin(hostname));
-
- if (!crypted_target) {
- return;
- }
-
- var query_string = WOT_SERVICE_API_SUBMIT +
- "?id=" + wot_prefs.witness_id +
- "&nonce=" + nonce +
- "&target=" + encodeURIComponent(btoa(
- wot_hash.bintostr(crypted_target)));
-
- var found = 0;
-
- for (var i = 0; i < WOT_APPLICATIONS; ++i) {
- if (testimonies[i] >= 0) {
- query_string += "&testimony_" + i + "=" + testimonies[i];
- ++found;
- }
- }
-
- query_string += "&lang=" + wot_util.getstring("language") +
- "&version=" + WOT_PLATFORM + "-" + WOT_VERSION;
-
- if (!found) {
- return;
- }
-
- var request = new XMLHttpRequest();
-
- request.open("GET", WOT_SERVICE_NORMAL +
- wot_crypto.authenticate_query(query_string));
-
- new wot_cookie_remover(request);
-
- request.onload = function(event)
- {
- try {
- if (request.status == 200) {
- var submit = request.responseXML.getElementsByTagName(
- WOT_SERVICE_XML_SUBMIT);
- if (submit) {
- wot_pending.clear(prefname);
- }
- }
- } catch (e) {
- dump("wot_api_submit.onload: failed with " + e + "\n");
- }
- };
-
- request.send(null);
- } catch (e) {
- dump("wot_api_submit.send: failed with " + e + "\n");
- }
- }
- };
-
- wot_api_submit.init();
-